package 寒假刷题;

import java.util.ArrayList;
import java.util.List;

public class 字母大小写全排列 {
    public static void main(String[] args) {
        String s = "a1b2";
        for (String s1 : letterCasePermutation(s)) {
            System.out.println(s1);
        }
    }
    public static List<String> letterCasePermutation(String s) {
        List<String> list = new ArrayList<>();
        char[] chars = s.toCharArray();
        backtrace(list, chars, 0, chars.length);
        return list;
    }

    private static void backtrace(List<String> list, char[] chars, int start, int length) {
        list.add(new String(chars));
        for (int i = start; i < length; i++) {
            char c = chars[i];
            if (!Character.isDigit(c)) {
                chars[i] ^= ' ';
                backtrace(list, chars, i + 1, length);
                chars[i] ^= ' ';
            }
        }
    }
}
